package com.hmall.item.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;
import java.util.List;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Autowired
    private  ItemService itemService;
    @Override
    public PageDTO getlist(Integer page, Integer size) {
        //分页构造器
        Page<Item> pageInfo = new Page<>(page, size);

        //分页查询
        Page<Item> page1 = itemService.page(pageInfo);
        long total = page1.getTotal();
        List<Item> records = page1.getRecords();
        PageDTO<Item> itemPageDTO = new PageDTO<>();
            itemPageDTO.setList(records);
            itemPageDTO.setTotal(total);
        return itemPageDTO;
    }
//修改
    @Override
    public void getupdate(Item item) {
        itemService.updateById(item);
    }
 //删除
    @Override
    public void getdelete(Long id) {
        itemService.removeById(id);
    }
//上架下架
    @Override
    public void update1(Long id, Integer status) {
        Item item = new Item();
        item.setId(id);
        item.setStatus(status);

        itemService.updateById(item);
    }
    //根据id的查询
    @Override
    public Item getById1(Long id) {
        return itemService.getById(id);
    }
//新增
    @Override
    public Boolean save1(Item item) {
        return itemService.save(item);
    }










}
